<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建项目信息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="engintype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="hemoney" id="hemoney" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目地点</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同计划开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="planstartdt" id="planstartdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">合同计划竣工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="planenddt" id="planenddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">实际开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">实际竣工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt" id="enddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">选择资料库模板</label>
                        <div class="layui-input-block">
                            <select id="tempid" name="tempid" lay-filter="tempid" ></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">项目概况</label>
                        <div class="layui-input-block">
                            <textarea id="gai" name="gai" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>参建单位</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">建设单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jian_unit" class="layui-input jian_unit" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="jian_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">设计单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="she_unit" class="layui-input she_unit" onclick="openPage('../public/choose_dealcom.php?dom=she_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="she_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=she_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">勘查单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="kan_unit" class="layui-input kan_unit" onclick="openPage('../public/choose_dealcom.php?dom=kan_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="kan_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=kan_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">施工单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="shi_unit" class="layui-input shi_unit" onclick="openPage('../public/choose_dealcom.php?dom=shi_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="shi_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=shi_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">监理单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="li_unit" class="layui-input li_unit" onclick="openPage('../public/choose_dealcom.php?dom=li_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="li_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=li_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">运营单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="yun_unit" class="layui-input yun_unit" onclick="openPage('../public/choose_dealcom.php?dom=yun_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="yun_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=yun_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">供应商单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="gong_unit" class="layui-input gong_unit" onclick="openPage('../public/choose_dealcom.php?dom=gong_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="gong_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=gong_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">制造商单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="zhi_unit" class="layui-input zhi_unit" onclick="openPage('../public/choose_dealcom.php?dom=zhi_unit&choose_type=check_box&page=engin','80%','80%')">
                            <div class="choose_div" id="zhi_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=zhi_unit&choose_type=check_box&page=engin','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<script>

    $("#commentForm").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    state_str += '<option value="'+key+'">'+state[key]+'</option>';
                }
                $("#state").html(state_str);


                var tempid_str = '<option value="">请选择</option>';
                var tempid = res.data.tempid;
                for (var key in tempid){
                    tempid_str += '<option value="'+tempid[key].id+'">'+tempid[key].name+'</option>';
                }
                $("#tempid").html(tempid_str);


                load_areas('areas', res.data.areas, 3);
                xmselect_dan('engintype', res.data.engintype);


                public_upload_file_load('upload_files');
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });


        form.on('submit(add)', function(data){
            data.field.jian_unit = get_choose_val('jian_unit');
            data.field.she_unit = get_choose_val('she_unit');
            data.field.kan_unit = get_choose_val('kan_unit');
            data.field.shi_unit = get_choose_val('shi_unit');
            data.field.li_unit = get_choose_val('li_unit');
            data.field.yun_unit = get_choose_val('yun_unit');
            data.field.gong_unit = get_choose_val('gong_unit');
            data.field.zhi_unit = get_choose_val('zhi_unit');

            var validRes = $("#commentForm").valid();

            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }


            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_engin_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });

    });

</script>
</body>
</html>
